import 'package:bloc/bloc.dart';
import '../../../base/base_state.dart';
import '../../../models/handle_state.dart';
import '../../../models/response_model.dart';
import '../../../net/http_config.dart';
import '../../../net/ltt_https.dart';
import '../../../widgets/easy_loading.dart';
import '../model/info_model.dart';
part 'information_detail_state.dart';

class InformationDetailCubit extends Cubit<InformationDetailState> {
  InformationDetailCubit() : super(InformationDetailState().init());

  /// 获取详情数据
  Future<void> geDetailData(String path, int entityId) async {
    XsEasyLoading.showLoading();
    ResponseModel? responseModel = await LttHttp()
        .request<InfoListModel>(path, params: {"entityId": entityId}, method: HttpConfig.get);
    XsEasyLoading.dismiss();
    state.model = responseModel.data;
    if (responseModel.code == 100200) {
      state.netState = NetState.dataSuccessState;
    } else if (responseModel.code == 404) {
      state.netState = NetState.error404State;
    } else if (responseModel.code == -100) {
      state.netState = NetState.timeOutState;
    } else {
      state.netState = NetState.errorShowRefresh;
    }
    emit(state.clone());
  }
}
